package servlet;

import com.google.gson.Gson;
import dao.Impl.StaffsDaoImpl;
import dao.StaffsDao;
import entitl.Staffs;
import vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author czl
 * @Date 2024-03-07
 */
@WebServlet("/staffs_delete")
public class staffsDelete extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));

        StaffsDao dao = new StaffsDaoImpl();
        int row=dao.delete(id);

        ResponseData responseData = new ResponseData();
        responseData.setMsg("删除成功");

        if(row!=1) {
            responseData.setMsg("删除成功");
            responseData.setCode(500);
        }

        String json = new Gson().toJson(responseData);
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        out.print(json);

        out.flush();
        out.close();
    }
}
